package com.zmn.oms.common.constant;

import com.google.common.collect.Lists;
import com.zmn.common.dictionary.DictModel;

import java.util.List;
import java.util.Objects;

/**
 * 派单常量
 *
 * @author xiangyang
 * @since 2020-06-02
 */
public class OrderDistributeConsts {

    /**
     * 派单方式
     */
    public final static int DISTRIBUTE_TYPE_MANUAL = 1; // 人工
    public final static int DISTRIBUTE_TYPE_AUTO = 2;   // 自动
    public final static int DISTRIBUTE_TYPE_PRE = 3;   // 预派

    /**
     * 派单路径
     */
    public final static int DISTRIBUTE_WAY_PLAT = 10;   // 平台直派
    public final static int DISTRIBUTE_WAY_SP = 20;     // 服务商派单

    /**
     * 派单入口 10.管理后台 20.服务商后台 30.工程师APP 40.改派申请
     */
    public final static int DISTRIBUTE_ENTRY_ADMIN = 10;       // 管理后台
    public final static int DISTRIBUTE_ENTRY_SP = 20;          // 服务商后台
    public final static int DISTRIBUTE_ENTRY_APP = 30;         // 工程师APP
    public final static int DISTRIBUTE_ENTRY_REDISTRIBUTE = 40;// 改派申请

    /**
     * 预派单来源
     */
    public final static int PRE_DISTRIBUTE_SOURCE_PLACE_AN_ORDER = 10; //下单

    /**
     * 派单规则
     * 0.未知 1000.返修 1010 返修优先级派单
     * 2000.工程师加单 2010.特殊服务商 2020.天猫差异派单 2030.渠道指定派单 2040.指定工程师派单
     * 3000.简单 3010.已派相似 3020.未派相似 3030.首轮优先 3040.权重分 3050.公平 3060.返修公平
     * 3070.普通多轮保护 3080 优先多轮保护 3090 分级权重 3100 家电突破公平
     */
    public final static int DISTRIBUTE_RULE_NONE = 0;

    public final static int DISTRIBUTE_RULE_REWORK = 1000;
    public final static int DISTRIBUTE_RULE_REWORK_PRIORITY = 1010;

    public final static int DISTRIBUTE_RULE_SPECIAL_ENADD = 2000;
    public final static int DISTRIBUTE_RULE_SPECIAL_SP = 2010;
    public final static int DISTRIBUTE_RULE_SPECIAL_TMALL = 2020;
    public final static int DISTRIBUTE_RULE_SPECIAL_CHANNEL = 2030;
    public final static int DISTRIBUTE_RULE_SPECIAL_APPOINT = 2040;

    public final static int DISTRIBUTE_RULE_SIMPLE = 3000;
    public final static int DISTRIBUTE_RULE_SIMILAR = 3010;
    public final static int DISTRIBUTE_RULE_MULTI = 3020;
    public final static int DISTRIBUTE_RULE_FIRST = 3030;
    public final static int DISTRIBUTE_RULE_RECOMMEND = 3040;
    public final static int DISTRIBUTE_RULE_FAIR = 3050;
    public final static int DISTRIBUTE_RULE_FAIR_REWORK = 3060;
    public final static int DISTRIBUTE_RULE_PROTECTION_ORDINARY = 3070;
    public final static int DISTRIBUTE_RULE_PROTECTION_PRIORITY = 3080;
    public final static int DISTRIBUTE_RULE_GRADING_RECOMMEND= 3090;
    public final static int DISTRIBUTE_RULE_HOME_APPLIANCES_FAIR= 3100;

    /**
     * 未自动派单原因
     * -1000、未获取到派单配置 -1010、未开启自动派单 -1020、测试单 -1030、状态不对 -1040、挂起
     * -1050、预约时间为空 -1060、用户信息不全 -1070、不在工作时间 -1080、未找到满足工程师
     * -1090、特殊派单 -1100、自动派单异常 -1110、渠道不自动派单 -1120、加单工程师 -1130、预约非今日跨网格
     */
    public final static int DISTRIBUTE_RULE_REASON_CONFIG = -1000;
    public final static int DISTRIBUTE_RULE_REASON_AUTO_CONFIG = -1010;
    public final static int DISTRIBUTE_RULE_REASON_TEST = -1020;
    public final static int DISTRIBUTE_RULE_REASON_STATUS = -1030;
    public final static int DISTRIBUTE_RULE_REASON_SUSPEND = -1040;
    public final static int DISTRIBUTE_RULE_REASON_DUTY_TIME = -1050;
    public final static int DISTRIBUTE_RULE_REASON_USER_INFO = -1060;
    public final static int DISTRIBUTE_RULE_REASON_WORK_TIME = -1070;
    public final static int DISTRIBUTE_RULE_REASON_FIND = -1080;
    public final static int DISTRIBUTE_RULE_REASON_SPECIAL = -1090;
    public final static int DISTRIBUTE_RULE_REASON_EXCEPTION = -1100;
    public final static int DISTRIBUTE_RULE_REASON_SPECIAL_CHANNEL = -1110;
    public final static int DISTRIBUTE_RULE_REASON_MASTER = -1120;
    public final static int DISTRIBUTE_RULE_REASON_DUTY_TIME_NOT_TODAY_ACROSS = -1130;

    /**
     * 无网格抢单不满足原因
     */
    public static final int UN_GRID_GRAB_MAX_DISTANCE_CODE = 10; // 最大抢单距离不满足
    public static final int UN_GRID_GRAB_SKILL_CODE = 20; // 技能不满足
    public static final int UN_GRID_GRAB_HAND_REWORK_CODE = 30; // 手头返修单不满足


    /**
     * 获取不满足原因
     * @param code
     * @return
     */
    public static String getUnGridGrabReason(Integer code) {
        switch (code) {
            case UN_GRID_GRAB_MAX_DISTANCE_CODE:
                return "最大抢单距离";
            case UN_GRID_GRAB_SKILL_CODE:
                return "技能";
            case UN_GRID_GRAB_HAND_REWORK_CODE:
                return "手头返修单";
            default:
                return "满足无网格抢单";
        }
    }


    /**
     * 需要记录派单快照的规则id集合
     */
    public final static List<Integer> distributeSnapshotList = Lists.newArrayListWithCapacity(16);
    static {
        distributeSnapshotList.add(DISTRIBUTE_RULE_SIMILAR);
        distributeSnapshotList.add(DISTRIBUTE_RULE_MULTI);
        distributeSnapshotList.add(DISTRIBUTE_RULE_FIRST);
        distributeSnapshotList.add(DISTRIBUTE_RULE_RECOMMEND);
        distributeSnapshotList.add(DISTRIBUTE_RULE_FAIR);
        distributeSnapshotList.add(DISTRIBUTE_RULE_FAIR_REWORK);
        distributeSnapshotList.add(DISTRIBUTE_RULE_PROTECTION_ORDINARY);
        distributeSnapshotList.add(DISTRIBUTE_RULE_PROTECTION_PRIORITY);
        distributeSnapshotList.add(DISTRIBUTE_RULE_GRADING_RECOMMEND);
        distributeSnapshotList.add(DISTRIBUTE_RULE_REASON_FIND);
        distributeSnapshotList.add(DISTRIBUTE_RULE_HOME_APPLIANCES_FAIR);
        distributeSnapshotList.add(DISTRIBUTE_RULE_REWORK_PRIORITY);
    }

    /**
     * 派单模式集合
     *
     * @return
     */
    public static List<DictModel> getDistributeWayList() {
        List<DictModel> items = Lists.newArrayList();
        items.add(new DictModel(OrderDistributeConsts.DISTRIBUTE_WAY_PLAT, "平台直派"));
        items.add(new DictModel(OrderDistributeConsts.DISTRIBUTE_WAY_SP, "服务商派单"));
        return items;
    }


    /**
     * 获取派单路径名称
     * @param wayId
     * @return
     */
    public static String getDistributeWayName(Integer wayId) {
        if (Objects.isNull(wayId)) {
            return "未知";
        }
        switch (wayId) {
            case DISTRIBUTE_WAY_PLAT:
                return "平台直派";
            case DISTRIBUTE_WAY_SP:
                return "服务商派单";
            default:
                return "未知";
        }
    }

    /**
     * 获取派单规则名称
     * @param ruleId
     * @return
     */
    public static String getDistributeRuleName(Integer ruleId) {
        if (Objects.isNull(ruleId)) {
            return "未知";
        }
        switch (ruleId) {
            case DISTRIBUTE_RULE_REWORK:
                return "返修";
            case DISTRIBUTE_RULE_REWORK_PRIORITY:
                return "返修优先级自动派规则";
            case DISTRIBUTE_RULE_SPECIAL_ENADD:
                return "工程师加单";
            case DISTRIBUTE_RULE_SPECIAL_SP:
                return "特殊服务商";
            case DISTRIBUTE_RULE_SPECIAL_TMALL:
                return "天猫差异派单";
            case DISTRIBUTE_RULE_SPECIAL_CHANNEL:
                return "渠道指定派单";
            case DISTRIBUTE_RULE_SPECIAL_APPOINT:
                return "指定工程师派单";
            case DISTRIBUTE_RULE_SIMPLE:
                return "简单";
            case DISTRIBUTE_RULE_SIMILAR:
                return "已派相似";
            case DISTRIBUTE_RULE_MULTI:
                return "未派相似";
            case DISTRIBUTE_RULE_FIRST:
                return "首轮派规则";
            case DISTRIBUTE_RULE_RECOMMEND:
                return "权重派规则";
            case DISTRIBUTE_RULE_FAIR:
                return "公平派规则";
            case DISTRIBUTE_RULE_FAIR_REWORK:
                return "返修公平派规则";
            case DISTRIBUTE_RULE_PROTECTION_ORDINARY:
                return "普通多轮保护派规则";
            case DISTRIBUTE_RULE_PROTECTION_PRIORITY:
                return "优先多轮保护派规则";
            case DISTRIBUTE_RULE_GRADING_RECOMMEND:
                return "分级派规则";
            case DISTRIBUTE_RULE_HOME_APPLIANCES_FAIR:
                return "家电突破-公平规则";
            default:
                return "未知";
        }
    }

    /**
     * 获取不可派单规则名称
     * @param ruleId
     * @return
     */
    public static String getNonDistributeRuleName(Integer ruleId) {
        if (Objects.isNull(ruleId)) {
            return "未知";
        }
        switch (ruleId) {
            case DISTRIBUTE_RULE_REASON_CONFIG:
                return "未获取到派单配置";
            case DISTRIBUTE_RULE_REASON_AUTO_CONFIG:
                return "未开启自动派单";
            case DISTRIBUTE_RULE_REASON_TEST:
                return "测试单";
            case DISTRIBUTE_RULE_REASON_STATUS:
                return "状态不对";
            case DISTRIBUTE_RULE_REASON_SUSPEND:
                return "挂起";
            case DISTRIBUTE_RULE_REASON_DUTY_TIME:
                return "预约时间为空";
            case DISTRIBUTE_RULE_REASON_USER_INFO:
                return "用户信息不全";
            case DISTRIBUTE_RULE_REASON_WORK_TIME:
                return "不在工作时间";
            case DISTRIBUTE_RULE_REASON_FIND:
                return "未找到满足工程师";
            case DISTRIBUTE_RULE_REASON_SPECIAL:
                return "特殊派单";
            case DISTRIBUTE_RULE_REASON_EXCEPTION:
                return "自动派单异常";
            case DISTRIBUTE_RULE_REASON_SPECIAL_CHANNEL:
                return "该渠道订单不自动派单";
            case DISTRIBUTE_RULE_REASON_MASTER:
                return "加单工程师不满足";
            case DISTRIBUTE_RULE_REASON_DUTY_TIME_NOT_TODAY_ACROSS:
                return "预约时间非今日不进行跨网格派单";
            default:
                return "未知";
        }
    }

    /**
     * 派单业务类型 0.未知 1.C 2.F 3.B 100.特殊
     */
    public final static int DISTRIBUTE_BIZ_TYPE_C = 1;           // C
    public final static int DISTRIBUTE_BIZ_TYPE_F = 2;           // F
    public final static int DISTRIBUTE_BIZ_TYPE_B = 3;           // B
    public final static int DISTRIBUTE_BIZ_TYPE_SPECIAL = 100;   // 特殊

    /**
     * 特殊派单类型 1.特殊服务商 2.天猫差异派单 3.渠道指定派单
     */
    public final static int SPECIAL_DISTRIBUTE_TYPE_SP = 1;              // 特殊服务商
    public final static int SPECIAL_DISTRIBUTE_TYPE_TMALL = 2;           // 天猫差异派单
//    public final static int SPECIAL_DISTRIBUTE_TYPE_CHANNEL = 3;         // 渠道指定工程师派单

    /**
     * 工作网格类型：1主网格，2副网格
     */
    public final static int WORKSPACE_TYPE_MAIN = 1;           // 主网格
    public final static int WORKSPACE_TYPE_SLAVE = 2;          // 副网格

    /**
     * 派单网格：1网格外，2网格内，3跨网格
     */
    public final static int DISTRIBUTE_GRID_OUT = 1;   // 网格外
    public final static int DISTRIBUTE_GRID_IN = 2;    // 网格内
    public final static int DISTRIBUTE_GRID_ACROSS = 3; // 跨网格

    /**
     * 跨网格redis过期时间
     */
    public final static int ACROSS_DISTRIBUTE_WAIT_TIME = 30; // 单位秒

    /**
     * 工程师新单派单分组
     */
    // 默认组0
    public final static int DISTRIBUTE_GROUP_NEW_NONE = 0;
    // 组1：主网格-主技能-最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_ONE = 1;
    // 组2：主网格-主技能-非最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_TWO = 2;
    // 组3：主网格-非主技能-最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_THREE = 3;
    // 组4：主网格-非主技能-非最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_FOUR = 4;
    // 组5：副网格-主技能-最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_FIVE = 5;
    // 组6：副网格-主技能-非最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_SIX = 6;
    // 组7：副网格-非主技能-最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_SEVEN = 7;
    // 组8：副网格-非主技能-非最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_EIGHTH = 8;
    // 组9：网格外-主技能-最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_NINE = 9;
    // 组10：网格外-主技能-非最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_TEN = 10;
    // 组11：网格外-非主技能-最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_ELEVEN = 11;
    // 组12：网格外-非主技能-非最佳库存
    public final static int DISTRIBUTE_GROUP_NEW_TWELVE = 12;


    /**
     * 工程师返修单派单分组
     */
    // 默认组0
    public final static int DISTRIBUTE_GROUP_REWORK_NONE = 0;
    // 组1：主网格-主技能
    public final static int DISTRIBUTE_GROUP_REWORK_ONE = 1;
    // 组2：主网格-非主技能
    public final static int DISTRIBUTE_GROUP_REWORK_TWO = 2;
    // 组3：副网格-主技能
    public final static int DISTRIBUTE_GROUP_REWORK_THREE = 3;
    // 组4：副网格-非主技能
    public final static int DISTRIBUTE_GROUP_REWORK_FOUR = 4;

    /**
     * 工程师派单校验（工程师系统级别校验）不满足原因分类集合
     * 目前只有平台直派-返修优先级自动派使用
     */
    // 状态不满足
    public final static List<Integer> ENGINEER_NON_DISTRIBUTE_REASON_STATUS = Lists.newArrayList(10, 20, 40, 50, 80, 90, 110, 120, 121, 130, 140);
    // 城市不满足
    public final static List<Integer> ENGINEER_NON_DISTRIBUTE_REASON_CITY = Lists.newArrayList(60, 70, 190, 200);
    // 技能不满足
    public final static List<Integer> ENGINEER_NON_DISTRIBUTE_REASON_SKILL = Lists.newArrayList(30, 150, 160);

}
